﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace DataStructure.Chapter1
{
    class TimingTest
    {
       

        private static void CompareAddPerformance()
        {
            Timing tObj = new Timing();

            int count = 1000 * 1000;
            ArrayList al = new ArrayList(count);
            tObj.StartTime();
            for (int i = 0; i < count; i++)
            {
                al.Add(i);
            }
            tObj.StopTime();
            Console.WriteLine("time (.NET):" + tObj.Result().TotalSeconds);

            MyCollection myc = new MyCollection(count);
            tObj.StartTime();
            for (int i = 0; i < count; i++)
            {
                myc.Add(i);
            }
            tObj.StopTime();
            Console.WriteLine("time (.NET):" + tObj.Result().TotalSeconds);
        }

        private static Timing TimingTesting1()
        {
            int[] nums = new int[100000];
            BuildArray(nums);
            Timing tObj = new Timing();
            tObj.StartTime();
            DisplayNums(nums);
            tObj.StopTime();
            Console.WriteLine();
            Console.WriteLine("time (.NET):" + tObj.Result().TotalSeconds);
            return tObj;
        }
      
        static void BuildArray(int[] arr)
        {
            for (int i = 0; i <= 99999; i++)
                arr[i] = i;
        }
        
        static void DisplayNums(int[] arr)
        {
            for (int i = 0; i <= arr.GetUpperBound(0); i++)
                Console.Write(arr[i] + "");
        }
    }

    /// <summary>
    /// Implement your collection
    /// </summary>
    public class MyCollection : CollectionBase
    {
        public MyCollection()
        {
                
        }
        public MyCollection(int capacity)
        {
            InnerList.Capacity = capacity;
        }

        public void Add(Object item)
        {
            InnerList.Add(item);
        }
        public void Remove(Object item)
        {
            InnerList.Remove(item);
        }
        public new void Clear()
        {
            InnerList.Clear();
        }
        public new int Count()
        {
            return InnerList.Count;
        }
        public void Insert(int index, object item)
        {
            InnerList.Insert(index, item);
        }

        public bool Contains(object item)
        {
           return  InnerList.Contains(item);
        }

        public int IndexOf(object item)
        {
            return InnerList.IndexOf(item);
        }

        public void RemoveAt(int index)
        {
            InnerList.RemoveAt(index);
        }
    }
    
}
